-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert createWasm
async/await where possible
#23157
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sbc100
force-pushed
the
await_createWasm
branch
from
December 15, 2024 01:53
09be374
to
f2b5976
Compare
sbc100
added a commit
to sbc100/emscripten
that referenced
this pull request
Dec 16, 2024
This is a debug feature that means users who did not await the promise and tried to access stuff directly on it would see a nice error message. However with the advent of more usage of async/await, for example in \emscripten-core#23157 it is not always the ready promise that gets returned to the user but a language-generated promise from an `await` call. We could try to jump through more hoops to continue to support this debug feature, but I don't think added complexity in the toolchain or the generated code would be worth it. Split out from emscripten-core#23157.
sbc100
added a commit
to sbc100/emscripten
that referenced
this pull request
Dec 16, 2024
This is a debug feature that means users who did not await the promise and tried to access stuff directly on it would see a nice error message. However with the advent of more usage of async/await, for example in \emscripten-core#23157 it is not always the ready promise that gets returned to the user but a language-generated promise from an `await` call. We could try to jump through more hoops to continue to support this debug feature, but I don't think added complexity in the toolchain or the generated code would be worth it. Split out from emscripten-core#23157.
sbc100
added a commit
that referenced
this pull request
Dec 16, 2024
This is a debug feature that means users who did not await the promise and tried to access stuff directly on it would see a nice error message. However with the advent of more usage of async/await, for example in \#23157 it is not always the ready promise that gets returned to the user but a language-generated promise from an `await` call. We could try to jump through more hoops to continue to support this debug feature, but I don't think added complexity in the toolchain or the generated code would be worth it. Split out from #23157.
sbc100
force-pushed
the
await_createWasm
branch
6 times, most recently
from
December 17, 2024 21:10
b85a441
to
3106ca5
Compare
sbc100
commented
Dec 17, 2024
sbc100
commented
Dec 17, 2024
sbc100
force-pushed
the
await_createWasm
branch
from
December 17, 2024 21:34
3106ca5
to
185bc2a
Compare
sbc100
changed the title
Allow the createWasm function to use async/await where possible
Convert createWasm async/await where possible
Dec 17, 2024
sbc100
changed the title
Convert createWasm async/await where possible
Convert Dec 17, 2024
createWasm
async/await where possible
kripken
reviewed
Dec 17, 2024
sbc100
force-pushed
the
await_createWasm
branch
from
December 17, 2024 22:54
185bc2a
to
d608121
Compare
sbc100
added a commit
to sbc100/emscripten
that referenced
this pull request
Dec 18, 2024
Once we start using `async` for for this function then `new` stops working: emscripten-core#23157. Using `new` in this was was always an antipattern but there was nothing stopping users from doing this.
sbc100
added a commit
to sbc100/emscripten
that referenced
this pull request
Dec 18, 2024
Once we start using `async` for for this function then `new` stops working: emscripten-core#23157. Using `new` in this was was always an antipattern but there was nothing stopping users from doing this.
sbc100
added a commit
to sbc100/emscripten
that referenced
this pull request
Dec 18, 2024
Once we start using `async` for for this function then `new` stops working: emscripten-core#23157. Using `new` in this was was always an antipattern but there was nothing stopping users from doing this.
sbc100
added a commit
to sbc100/emscripten
that referenced
this pull request
Dec 18, 2024
Once we start using `async` for for this function then `new` stops working: emscripten-core#23157. Using `new` in this was was always an antipattern but there was nothing stopping users from doing this.
sbc100
added a commit
to sbc100/emscripten
that referenced
this pull request
Dec 18, 2024
Once we start using `async` for for this function then `new` stops working: emscripten-core#23157. Using `new` in this was was always an antipattern but there was nothing stopping users from doing this.
hedwigz
pushed a commit
to hedwigz/emscripten
that referenced
this pull request
Dec 18, 2024
This is a debug feature that means users who did not await the promise and tried to access stuff directly on it would see a nice error message. However with the advent of more usage of async/await, for example in \emscripten-core#23157 it is not always the ready promise that gets returned to the user but a language-generated promise from an `await` call. We could try to jump through more hoops to continue to support this debug feature, but I don't think added complexity in the toolchain or the generated code would be worth it. Split out from emscripten-core#23157.
sbc100
added a commit
to sbc100/emscripten
that referenced
this pull request
Dec 18, 2024
Once we start using `async` for for this function then `new` stops working: emscripten-core#23157. Using `new` in this was was always an antipattern but there was nothing stopping users from doing this.
sbc100
added a commit
to sbc100/emscripten
that referenced
this pull request
Dec 18, 2024
Once we start using `async` for for this function then `new` stops working: emscripten-core#23157. Using `new` in this was was always an antipattern but there was nothing stopping users from doing this.
sbc100
added a commit
to sbc100/emscripten
that referenced
this pull request
Dec 18, 2024
Once we start using `async` for for this function then `new` stops working: emscripten-core#23157. Using `new` in this was was always an antipattern but there was nothing stopping users from doing this.
sbc100
added a commit
to sbc100/emscripten
that referenced
this pull request
Dec 18, 2024
Once we start using `async` for for this function then `new` stops working: emscripten-core#23157. Using `new` in this was was always an antipattern but there was nothing stopping users from doing this.
sbc100
added a commit
to sbc100/emscripten
that referenced
this pull request
Dec 18, 2024
Once we start using `async` for for this function then `new` stops working: emscripten-core#23157. Using `new` in this was was always an antipattern but there was nothing stopping users from doing this.
sbc100
added a commit
to sbc100/emscripten
that referenced
this pull request
Dec 18, 2024
Once we start using `async` for for this function then `new` stops working: emscripten-core#23157. Using `new` in this was was always an antipattern but there was nothing stopping users from doing this.
sbc100
added a commit
that referenced
this pull request
Dec 18, 2024
Once we start using `async` for for this function then `new` stops working: #23157. Using `new` in this was was always an antipattern but there was nothing atopping users from doing this.
sbc100
force-pushed
the
await_createWasm
branch
2 times, most recently
from
December 18, 2024 22:59
a7bb4fa
to
9e0033a
Compare
sbc100
force-pushed
the
await_createWasm
branch
from
December 18, 2024 23:02
9e0033a
to
19b9a70
Compare
kripken
reviewed
Dec 18, 2024
sbc100
force-pushed
the
await_createWasm
branch
from
December 18, 2024 23:55
19b9a70
to
828202a
Compare
The advantage if using `await` in the cases where we can is that it avoids the generation or wrapper function for each export. So instead of ``` var wasmExport = createWasm(); // returns empty object ... var malloc = ((..) => (malloc = wasmExports['malloc'])() ``` We can just generate: ``` var wasmExport = createWasm(); // returns empty object ... var malloc = wasmExports['malloc']; ``` This only currently works in MODULARIZE mode where the code is running inside a factory function. Otherwise it would end up using top-level-await. One wrinkle here is that this is not currently supported when closure is enabled because we run closure only on the contents of the factory function so closure ends up seeing this as a top level await when its not.
kripken
reviewed
Dec 19, 2024
sbc100
force-pushed
the
await_createWasm
branch
from
December 19, 2024 01:23
828202a
to
ce417c6
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The advantage if using
await
in the cases where we can is that it avoids the generation or wrapper function for each export.So instead of
We can just generate:
This only currently works in MODULARIZE mode where the code is running inside a factory function. Otherwise it would end up using top-level-await.
One wrinkle here is that this is not currently supported when closure is enabled because we run closure only on the contents of the factory function so closure ends up seeing this as a top level await when its not.
There are two minor observable effects of this change:
MODULARIZE
mode its no longer possible to callnew Foo()
with factory function. We already added a warning for this debug builds in Assert ifMODULARIZE
factory function is used withnew
. #23210.await
for createWasm to return, therun
method can run on first call, which means it runsmain
on first call, which means main will now run beforepostjs
code, just like it would with sync instantiation.